@extends('layouts.back_stage')
@section('style')
    @parent
    <link rel="stylesheet" href="{{env('CDN_DOMAIN_NAME')}}/css/createPro.css"/>
    <link href="{{env('CDN_DOMAIN_NAME')}}/css/bootstrap-fileinput.css" rel="stylesheet">
    <style>
        .form_ul{
            display: block;
            clear: both;
            margin-bottom: 40px;
        }
        .form_li_add{
            width:250px;
            margin-bottom: 40px;
            margin-right:20px;
            position:relative;
        }
        .form_li_add .form-control{
            display: inline-block;
            width:200px;
        }
        .color_check{
            width:200px;
            padding:0;
            float:none;
        }
        .form-group{
            overflow: hidden;
        }
        .form_add{
            float:right;
            margin:0;
            margin-top:10px;
        }
    </style>
@endsection
@section('content')
    <div class="container">
        <div class="row">
            <div style="margin:30px;"><h3 >添加搭配</h3></div>
            <div style="width:90%;margin-left:100px;">
                    <div class="form-group">
                        <ul class="form_ul">
                            @if(count($infos) > 0)
                            @foreach($infos as $k => $v)
                            <li class="form_li form_li_add">
                                <h3>搭配</h3>
                                款号：
                                <input type="text" list="griard_list" class="form-control griard_check" value="{{ $v->girard }}" placeholder="请输入款号">
                                颜色：
                                <select class="sel_inp color_check">
                                    <option value="{{ $v->color }}">{{ $v->color }} {{ $v->bom }}</option>
                                </select>
                                <div class="form-group"><button class='form_add btn btn-success'>保存</button></div>
                            </li>
                            @endforeach
                            @endif
                            @for($i=0;$i<6-count($infos);$i++)
                            <li class="form_li form_li_add">
                                <h3>搭配</h3>
                                款号：
                                <input type="text" list="griard_list" class="form-control griard_check"  placeholder="请输入款号">
                                颜色：
                                <select class="sel_inp color_check">
                                </select>
                                <div class="form-group"><button class='form_add btn btn-success'>保存</button></div>
                            </li>
                                @endfor
                        </ul>
                        <ul class="form_ul">
                            <li class="form_li form_li_add">
                                <form>
                                    <div class="form-group" id="uploadForm" enctype='multipart/form-data'>
                                        <h3>上传图片</h3>
                                        <div class="fileinput fileinput-new" data-provides="fileinput"  id="exampleInputUpload">
                                            <div class="fileinput-new thumbnail" style="width: 200px;height: auto;max-height:150px;">
                                                <img id='picImg' src="{{env('CDN_DOMAIN_NAME') }}/upload/{{ $res->img }}" alt="请点击下面按钮选择照片" />
                                            </div>
                                            <p class="upload_tips"></p>
                                            <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;"></div>
                                            <div>
                                                <span class="btn btn-primary btn-file">
                                                    <span class="fileinput-new">选择照片</span>
                                                    <span class="fileinput-exists">换一张</span>
                                                    <input type="file" name="pic1" id="picID" onchange="loadImage(this)" accept="image/gif,image/jpeg,image/x-png"/>
                                                </span>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </li>
                        </ul>
                        <ul class="form_ul">
                            <li class="form_li form_li_add">
                                <a href="index"><button class='btn btn-success btn-save-success'>填写完成 返回波段首页</button></a>
                            </li>
                        </ul>
                        <datalist id="griard_list">
                            @if(count($pro) > 0)
                                @foreach($pro as $k=>$v)
                                    <option value="{{ $v->girard }}"></option>
                                    @endforeach
                                @endif
                        </datalist>
                    </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        (function ($) {     //获取URL参数
            $.getUrlParam = function (name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]); return null;
            }
        })(jQuery);
        $('.griard_check').blur(function () {
           var that = $(this);
           var getGirard = that.val();
           $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                url:'/waveband/choiceClothColor',
                type:'post',
                dataType:'json',
                data:{
                    girard:getGirard
                },
                success:function (event) {
                    that.next().children().remove();
                    for(var i = 0;i<event.info.length;i++){
                        that.next().append('<option value='+event.info[i].id+'>'+event.info[i].color+' '+event.info[i].bom+'</option>');

                    }
                }
            })
        });
        $('.form_add').click(function () {
            var that = $(this);
            var girard_info = that.parent().siblings('.griard_check').val();
            var color_info = that.parent().siblings('.color_check').val();
            var band_id = $.getUrlParam('id');
            if(girard_info == '' || color_info == ''){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("没有填写款号或颜色哦");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }else{
                $.ajax({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                    },
                    url:'/waveband/increaseBandDetail',
                    type:'post',
                    dataType:'json',
                    data:{
                        band_id:band_id,
                        product_id:color_info
                    },
                    success:function (event) {
                        console.log(event)
                        if(event.success = 'true'){
                            that.text('修改');
                        }
                    }
                })
            }
        });
        var domain = "{{ env('UPLOAD_IMG_DOMAIN') }}";
    </script>
@endsection
@section('style')
    @parent
    <link href="{{env('CDN_DOMAIN_NAME')}}/css/waveband.css?v0.0.2" rel="stylesheet">
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/bootstrap-fileinput.js?v0.0.1" type="text/javascript"></script>
@endsection